<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>javascript 阶段</title>
    <style>
        div {
            padding: 10px ;
            width: 300px;
            background-color: #ccc;
        }
        img {
            width: 300px;
            vertical-align: middle;
        }
    </style>
</head>
<body>
   
    <div class="box">
        <img src="./images/baidu.png" alt="百度LOGO">
    </div>

    <script>
        // 获取img标签
        var img = document.querySelector(".box img");
        // 设置属性
        var srcV = "./images/taobao.png";
        img.setAttribute("src", srcV);
        img.setAttribute("alt","淘宝");

        // 获取属性值
        var v1 = img.getAttribute("src"); 
        var v2 = img.getAttribute("alt"); 
        console.log(v1);
        console.log(v2);

        // 删除属性
        // var res = img.removeAttribute("src");
        // console.log(res);// undefined


        // 总结：
            // 针对标签属性进行操作 （class , id , src ,alt , href）

    </script>
</body>
</html>